/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.scaroo.injectedgallery;

import com.google.common.base.Functions;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.sun.faces.util.CollectionsUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.enterprise.inject.Alternative;
import javax.inject.Inject;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import com.google.common.base.Function;

/**
 *
 * @author alexandremazari
 */
@Entity
@Alternative
public class Gallery {

    public final static int defaultId = 0;
    @Id
    private int id;
    private String name;
    @Inject
    @OneToOne
    private Photographer photographer;

//    public Gallery(){}
//
//    public Gallery(String name, Photographer photographer, Collection<Album> albums) {
//        this.name = name;
//
//        this.photographer = photographer;
//        this.albums = albums;
//    }
    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public Photographer getPhotographer() {
        return photographer;
    }

    public void setPhotographer(Photographer photographer) {
        this.photographer = photographer;
    }
    @OneToMany
    private Collection<Album> albums;

    public Collection<Album> getAlbums() {
        return albums;
    }

    public void setAlbums(Collection<Album> albums) {
        this.albums = albums;
    }

    public Collection<Picture> getCovers() {

        return Collections2.transform(albums, new Function<Album, Picture>() {

            public Picture apply(Album from) {
                return from.getCover();
            }
        });

    }
}
